/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pneuservis.backend.to;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import pneuservis.backend.entities.OrderPneu;
import pneuservis.backend.entities.ServicePneu;
import pneuservis.backend.others.OrderStatus;

/**
 *
 * @author Admin
 */
public class OrderPneuTO {
    private Long id;
    private TyreTypeTO tyreType;
    private int tyresCount;
    private OrderStatus status;
    private CustomerTO customer;
    private String vehicleBrand;
    private List<ServicePneuTO> servicePneus = new ArrayList();

    public OrderPneuTO() {
    }

    public OrderPneuTO(OrderPneu orderPneu) {
        if (orderPneu == null) {
            throw new IllegalArgumentException();
        }
        this.id = orderPneu.getId();
        this.tyreType = new TyreTypeTO(orderPneu.getTyreType());
        this.tyresCount = orderPneu.getTyresCount();
        this.status = orderPneu.getStatus();
        this.customer = new CustomerTO(orderPneu.getCustomer());
        this.vehicleBrand = orderPneu.getVehicleBrand();
        for (ServicePneu s : orderPneu.getServicePneus()){
            this.servicePneus.add(new ServicePneuTO(s));
        }
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public TyreTypeTO getTyreType() {
        return tyreType;
    }

    public void setTyreType(TyreTypeTO tyreType) {
        this.tyreType = tyreType;
    }

    public int getTyresCount() {
        return tyresCount;
    }

    public void setTyresCount(int tyresCount) {
        this.tyresCount = tyresCount;
    }

    public OrderStatus getStatus() {
        return status;
    }

    public void setStatus(OrderStatus status) {
        this.status = status;
    }

    public CustomerTO getCustomer() {
        return customer;
    }

    public void setCustomer(CustomerTO customer) {
        this.customer = customer;
    }

    public String getVehicleBrand() {
        return vehicleBrand;
    }

    public void setVehicleBrand(String vehicleBrand) {
        this.vehicleBrand = vehicleBrand;
    }

    public List<ServicePneuTO> getServicePneus() {
        return servicePneus;
    }

    public void setServicePneus(List<ServicePneuTO> servicePneus) {
        this.servicePneus = servicePneus;
    }
    
    public BigDecimal getSum() {
        BigDecimal sum = tyreType.getPrice().multiply(new BigDecimal(tyresCount));
        for(ServicePneuTO s : servicePneus){
            sum = sum.add(s.getPrice());
        }
        return sum;
    }
    
    public OrderPneu toOrderPneu(){
        OrderPneu result = new OrderPneu();
        result.setId(id);
        result.setCustomer(customer.toCustomer());
        result.setStatus(status);
        result.setTyreType(tyreType.toTyreType());
        result.setTyresCount(tyresCount);
        result.setVehicleBrand(vehicleBrand);
        for (ServicePneuTO s : servicePneus){
            result.getServicePneus().add(s.toServicePneu());
        }
        return result;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 23 * hash + Objects.hashCode(this.id);
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final OrderPneuTO other = (OrderPneuTO) obj;
        if (!Objects.equals(this.id, other.id)) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "OrderPneuTO{" + "id=" + id + '}';
    }
}
